package com.japher.hackson.requests;

import com.baidu.common.async_http.AbstractParser;
import com.baidu.common.async_http.AbstractRequester;
import com.baidu.common.json.JsonSerializer;
import com.baidu.common.net.HttpRequestData;
import com.baidu.common.utils.AppLog;
import com.japher.hackson.response.BaseResponse;
import com.japher.hackson.response.CommentResponse;

public class LoadCommentRequest extends AbstractRequester {
    
    private String longtitude;
    private String latitude;
    private float distance;
    
    
    public LoadCommentRequest(String longtitude, String latitude, float distance) {
        this.latitude = latitude;
        this.longtitude = longtitude;
        this.distance = distance;
    }
    
    @Override
    protected HttpRequestData createSendData() {
        
        HacksonReuqestData data = new HacksonReuqestData(HacksonReuqestData.BASE_URL  + "/essay/near");
        data.setAppUrl(false);
        data.setSecurity(false);
        data.setGzip(false);
        
        data.addGetParam("lng", longtitude);
        data.addGetParam("lat", latitude);
        data.addGetParam("distance", (int)distance + "");
        
        return data;
    }
    
    @Override
    protected AbstractParser createParser() {
        return new LoadCommentsParser();
    }
    
    public static class LoadCommentsParser extends AbstractParser
    {

        @Override
        protected AbstractParser createParser() {
            return new LoadCommentsParser();
        }

        @Override
        protected BaseResponse jsonParse(String json) {
            AppLog.debug(this, json);
            BaseResponse res = JsonSerializer.getInstance().deserialize(json, CommentResponse.class);
            if (res == null) {
                res = new BaseResponse();
                res.setStatus(BaseResponse.ERR_CODE_JSON_PARSE);
            }
            return res;
        }
        
    }
    
//    public static class DoRecallResponse extends BaseResponse {
//        // nothin special
//    }
    
}
